/*
 * miniFreeRTOS SOC System emulation.
 *
 * Copyright (c) 2024- yanl1229@163.com.
 * Written by yanl1229
 *
 * This code is licensed under the GPL.
 */
#ifndef SEMAPHORE_H
#define SEMAPHORE_H

#include "list.h"
#include "task.h"
#include "semaphore.h"

/*
 * 消息队列管理结构
 */
struct semaphore
{
    volatile list_head waiter_list;           /* 等待信号量释放任务列表 */
    volatile uint32_t count;         /* 信号量计数器 */
};


/*
 * 创建二值信号量
 */
extern struct semaphore * semaphore_create();

/**
 * 删除信号量
 */
extern void semaphore_delete(struct semaphore *sem);
/**
 * 释放信号量
 */
extern uint32_t semaphore_up(struct semaphore * sem);
/**
 * 获取信号量
 */
extern uint32_t semaphore_down(struct semaphore * sem);

/**
 * 释放信号量
 */
extern uint32_t semaphore_up_irq(struct semaphore * sem);
/**
 * 获取信号量
 */
extern uint32_t semaphore_down_irq(struct semaphore * sem);

#endif